package com.coocaa.ops.api.base.third.rec.feign;

import com.coocaa.ops.api.base.properties.HostProperties;
import feign.*;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.hystrix.HystrixFeign;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author zen
 * @date 2020-08-04 16:44
 * @description
 */
@Configuration
@Import(FeignClientsConfiguration.class)
public class GetRecStreamFeignConfigure {
    private static final int CONNECT_TIMEOUT_MILLIS = 1000;

    private static final int READ_TIMEOUT_MILLIS = 1000;


    @Bean
    public GetRecStreamFeignClient getRecStreamFeignClient(Encoder encoder, Decoder decoder
            , Contract contract, Client client, GetRecStreamFallBackFactory fallBackFactory
            , HostProperties hostProperties) {
        return HystrixFeign.builder()
                .encoder(encoder)
                .decoder(decoder)
                .options(new Request.Options(CONNECT_TIMEOUT_MILLIS, READ_TIMEOUT_MILLIS))
                .retryer(new Retryer.Default())
                .logLevel(Logger.Level.FULL)
                .contract(contract)
                .client(client)
                .target(GetRecStreamFeignClient.class, hostProperties.getBigDataRec(), fallBackFactory);
    }



}
